package com.example.drss.asynctask;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.example.drss.DRSSActivity;
import com.example.drss.fragment.OneFragment;

import android.os.AsyncTask;

public class MyAsyncTask extends AsyncTask<String, Void, String> {
	
	OneFragment fragment;
	public MyAsyncTask(OneFragment fragment){
		this.fragment=fragment;
	}

	@Override
	protected String doInBackground(String... params) {
		String url=params[0];
		HttpGet httpGet=new HttpGet(url);
		HttpClient httpClient= new DefaultHttpClient();
		try {
			HttpResponse httpResponse=httpClient.execute(httpGet);
			int sc=httpResponse.getStatusLine().getStatusCode();
			if(sc==200){
				HttpEntity httpEntity=httpResponse.getEntity();
				String data=EntityUtils.toString(httpEntity);
				return data;
				//更新UI：发送消息->UI线程
				//获取消息对象
			}
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	//自动调用
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
		//4
		super.onPostExecute(result);
		//直接更新UI
		fragment.updateUI(result);
	}

}
